package com.example.nit.controller;

import com.alibaba.fastjson.JSON;
import com.example.nit.bean.ValueCategory;
import com.example.nit.bean.ValueCorrect;
import com.example.nit.listener.SparkStreaming2Listener;
import com.example.nit.listener.SparkStreaming4Listener;
import com.example.nit.utils.R;
import com.example.nit.whole.Reference;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

/**
 * @author Liu
 * @date 2022/12/9 9:22
 **/
@RestController
@RequestMapping("/spark2")
public class Streaming2Controller {

    @GetMapping("/getJudge")
    public R getJudge() {
        List<ValueCorrect> result = new ArrayList<>();
        if (Reference.Streaming2List!=null){
            for (String s : Reference.Streaming2List) {
                try {
                    ValueCorrect valueCorrect = JSON.parseObject(s, ValueCorrect.class);
                    result.add(valueCorrect);
                } catch (Exception e) {

                }
            }
            Reference.Streaming2List.clear();
        }

        return R.ok().put("result", result);
    }
}
